from src.utils import file_utils
import os


class VideoFolderInfo(object):
    '''
    视频文件路劲相关类
    --root_path
        origin.mp4
        jieshuo.mp4
        jieshuo.srt
        --chouzhen
            --origin_images
            --jieshuo_images
        --temp
            video_similary_dict.txt

    '''
    def __init__(self,root_path,use_srt):
        '''

        :param root_path: 视频根目录地址
        '''
        self.use_srt = use_srt
        # 相关视频MP4路径
        self.origin_mp4_file = os.path.join(root_path,'origin.mp4')
        self.origin_srt_file = os.path.join(root_path, 'origin.srt')
        self.origin_cut_mp4_file = os.path.join(root_path, 'origin_cut.mp4')
        self.jieshuo_mp4_file = os.path.join(root_path,'jieshuo.mp4')
        self.jieshuo_srt_file = os.path.join(root_path,"jieshuo.srt")
        self.jieshuo_srt_clean_file = os.path.join(root_path,'jieshuo_clean.srt')
        self.jieshuo_srt_remove_dirty_file = os.path.join(root_path,'jieshuo_remove_dirty.srt')


        # 相关视频抽帧保存路径
        self.origin_image_fold = os.path.join(root_path,"chouzhen/origin_images")
        self.jieshuo_image_fold = os.path.join(root_path,"chouzhen/jieshuo_images")
        self.temp_fold = os.path.join(root_path,'temp')


        # 临时视频相似index保存文件
        self.jieshuo_similary_save_text = os.path.join(root_path,"temp/similary.txt")
        self.jieshuoHeapSaveFolder = os.path.join(root_path,'temp/new_videos')
        self.jieshuoHeapSaveFolderEnglish = os.path.join(root_path, 'temp/new_videos_en')
        self.jieshuoHeapConvertFile = os.path.join(root_path,"temp/second_convert_file.txt")


        # 文案重写临时文件保存路径
        self.jieshuoSrtPath = os.path.join(root_path,'srt')
        self.jieshuoSrtAddPunctuationFileName = os.path.join(root_path,r"srt\add_punctuation.txt")
        self.jieshuoSrtAddPunctuationTempFileName = os.path.join(root_path, r"srt\add_punctuation_temp.txt")
        self.jieshuoSrtReduceTextFileName = os.path.join(root_path, r"srt\reduce_text.txt")
        self.jieshuoSrtRewriteFileName = os.path.join(root_path, r"srt\rewrite.txt1")
        self.jieshuoNewSrtPath = os.path.join(self.jieshuoSrtPath,"new.srt")
        self.jieshuoNewSrtPathEnglish = os.path.join(self.jieshuoSrtPath,'new_en.srt')

        self.finalVideoName = os.path.join(root_path,'final.mp4')
        self.finalVideoNameEnglish = os.path.join(root_path,"final_en.mp4")



        self._check_file_or_fold()



    def _check_file_or_fold(self):
        '''
        检查相关的文件，路径是否都存在
        :return:
        '''

        file_check_list = [self.origin_mp4_file,self.jieshuo_mp4_file]
        if self.use_srt:
            file_check_list.append(self.jieshuo_srt_file)
        for file in file_check_list:
            if not file_utils.check_file_exists(file):
                raise FileNotFoundError(f"{file} 不存在，请把相应文件复制过去！")

        fold_check_list = [self.origin_image_fold,self.jieshuo_image_fold,self.temp_fold,self.jieshuoHeapSaveFolder,self.jieshuoSrtPath,self.jieshuoHeapSaveFolderEnglish]
        for fold in  fold_check_list:
            file_utils.make_folds(fold)









